home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / pmpsrc11.zip / LEVEL2RX.C < prev    next >
Text File  |  1991-07-30  |  2KB  |  72 lines

  1. /*
  2.     level2rx.c -- Level 2 AX.25 packet processing
  3.  
  4.   Poor Man's Packet (PMP)
  5.   Copyright (c) 1991 by Andrew C. Payne    All Rights Reserved.
  6.  
  7.   Permission to use, copy, modify, and distribute this software and its
  8.   documentation without fee for NON-COMMERCIAL AMATEUR RADIO USE ONLY is hereby
  9.   granted, provided that the above copyright notice appear in all copies.
  10.   The author makes no representations about the suitability of this software
  11.   for any purpose.  It is provided "as is" without express or implied warranty.
  12.  
  13.     September, 1989
  14.      Andrew C. Payne
  15. */
  16.  
  17. /* ----- Includes ----- */
  18.  
  19. #include <stdio.h>
  20. #include <alloc.h>
  21. #include <dos.h>
  22. #include "pmp.h"
  23.  
  24. /* addrtous(p2)
  25.     Given a pointer to a level 2 packet, returns TRUE if the packet was
  26.     addressed to us.
  27. */
  28. static int addrtous(struct ax25_packet *p2)
  29. {
  30.     int    i;
  31.  
  32.     if(CompAX25Addr(&p2->dest,&MyCall))
  33.         return FALSE;
  34.  
  35.     if(p2->ndigis) {
  36.         for(i=0; i<p2->ndigis; i++) {
  37.             if(!p2->repeated[i])
  38.                 return FALSE;
  39.         }
  40.     }
  41.     return TRUE;
  42. }
  43.  
  44. /* AX25Level2(l1)
  45.     This routine is the level 2 upcall.   This routine is called once
  46.     for each recieved level1 packet.
  47.  
  48.     This routine handles logging packets in the debugging log,
  49.     dumping packets when not connected, and passing packets to the LAPB
  50.     routines.
  51. */
  52. void AX25Level2(struct ax25_level1 *p)
  53. {
  54.     struct    ax25_packet    *p2;
  55.  
  56.     if((p2 = AX25L1toL2(p)) == NULL)    /* bad packet */
  57.         return;
  58.  
  59. #ifdef TRACE
  60.     if(DebugMode)
  61.         LogPacket(p,1);         /* log incoming */
  62. #endif
  63.     Heard(p2);                /* nodes heard */
  64.  
  65.     if(!Connected())
  66.         ShowLevel2(p2);
  67.  
  68.     if(addrtous(p2))
  69.         AX25_Incoming(p2);
  70.  
  71.     free(p2);
  72. }